using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace RUPS
{
    public partial class StergeComandaClientForm : Form
    {
        string idComandaClient;
        public StergeComandaClientForm()
        {
            InitializeComponent();
            CenterToScreen();
        }

        private void StergeComandaClientForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'masivDBDataSet11.comenziClienti' table. You can move, or remove it, as needed.
            //this.comenziClientiTableAdapter.Fill(this.masivDBDataSet11.comenziClienti);
            SqlDataAdapter da = new SqlDataAdapter("select * from comenziClienti", comenziClientiTableAdapter.Connection);
            DataSet ds = new DataSet();
            da.Fill(ds, "comenziCl");
            this.comboBox2.DataSource = null;
            foreach (DataRow r in ds.Tables["comenziCl"].Rows)
            {
                comboBox2.Items.Add(r["idcomanda"].ToString());
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBox2.SelectedItem.ToString() != null)
            {
                textBox1.Text = "";
                textBox2.Text = "";

                idComandaClient = this.comboBox2.SelectedItem.ToString();
                SqlDataAdapter da = new SqlDataAdapter("select * from comenziClienti where idCOmanda=" + idComandaClient, comenziClientiTableAdapter.Connection);
                DataSet ds = new DataSet();
                ds.Tables.Clear();
                da.Fill(ds, "comenziClienti");
                if (ds.Tables["comenziClienti"] != null)
                {
                    string idCl = ds.Tables["comenziClienti"].Rows[0]["idClient"].ToString();
                    this.dateTimePicker1.Value = DateTime.Parse(ds.Tables["comenziClienti"].Rows[0]["dataComanda"].ToString());
                    this.dateTimePicker2.Value = DateTime.Parse(ds.Tables["comenziClienti"].Rows[0]["dataLivrare"].ToString());
                    string text = ds.Tables["comenziClienti"].Rows[0]["idClient"].ToString() + ",";
                    this.textBox2.Text = "";
                    this.textBox2.Text = idCl;

                    SqlDataAdapter da1 = new SqlDataAdapter("select * from clienti where id=" + idCl, this.comenziClientiTableAdapter.Connection);
                    DataSet ds1 = new DataSet();
                    da1.Fill(ds1, "clienti");
                    this.textBox1.Text = "";

                    if (ds1.Tables["clienti"].Rows[0]["nume"].ToString() != null)
                        textBox1.Text += "Nume: " + ds1.Tables["clienti"].Rows[0]["nume"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["prenume"].ToString() != null)
                        textBox1.Text += "Prenume: " + ds1.Tables["clienti"].Rows[0]["prenume"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["adresa1"].ToString() != null)
                        textBox1.Text += "Adresa: " + ds1.Tables["clienti"].Rows[0]["adresa1"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["adresa2"].ToString() != null)
                        textBox1.Text += "Adresa: " + ds1.Tables["clienti"].Rows[0]["adresa2"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["localitate"].ToString() != null)
                        textBox1.Text += "Localitate: " + ds1.Tables["clienti"].Rows[0]["localitate"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["telefon"].ToString() != null)
                        textBox1.Text += "Tel:" + ds1.Tables["clienti"].Rows[0]["telefon"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["email"].ToString() != null)
                        textBox1.Text += "Email:" + ds1.Tables["clienti"].Rows[0]["email"].ToString() + "\r\n";
                    if (ds1.Tables["clienti"].Rows[0]["tip"].ToString() != null)
                        textBox1.Text += "Tip:" + ds1.Tables["clienti"].Rows[0]["tip"].ToString();
                    ds1.Tables["clienti"].Rows.Clear();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlCommand comm = comenziClientiTableAdapter.Connection.CreateCommand();
            comm.CommandText = "delete from comenziClienti where idComanda=" + idComandaClient;
            if (comenziClientiTableAdapter.Connection.State == ConnectionState.Closed)
            {
                comenziClientiTableAdapter.Connection.Open();
            }
            comm.ExecuteNonQuery();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}